function approve(me, sellerId, status){
	_index = layer.confirm("确实审核它吗？该操作不能撤销。", {
		icon : 3,
		title : "操作提示",
		closeBtn : false,
		skin : "layui-layer-red",
		btn : [ "确定", "取消" ]
	}, 
	function() {
		me = me.parentNode;
		$.ajax({url:"shop/approve.do", data: { id: sellerId, status: status },async: true,success: function(result) {
			me.innerHTML = ["待审核","通过","未通过"][status] + "(<span style='color:#008B00;'>已审核</span>)";
		}});
		me.innerHTML = "<span style='color:#888;'>正在提交..</span>";
		layer.close(_index);
	});
}
function editerApprove(btn, status){
	var form = $($(btn).parents(".form").parent().children(".form")[0]);
	setField(form, "status", status);
	approve(btn, getField(form, "id"), status);
}
$(function(){
	var tableSource = new $.jqx.dataAdapter({
		dataType: "json",
		dataFields:[
			{ name: "id", type: "int" },
			{ name: "name", type: "string" },
			{ name: "contacts", type: "string" },
			{ name: "telephone", type: "string" },
			{ name: "cellphone", type: "string" },
			{ name: "positive_identity_card", type: "string" },
			{ name: "The_opposite_of_ID_card", type: "string" },
			{ name: "email", type: "string" },
			{ name: "status", type: "int" },
			{ name: "province", type: "string" },
			{ name: "city", type: "string" },
			{ name: "district", type: "string" },
			{ name: "street", type: "string" },
			{ name: "detailed_address", type: "string" },
			{ name: "description", type: "string" },
			{ name: "detailed", type: "string" },
			{ name: "logo", type: "string" },
			{ name: "idcard", type: "string" },
			{ name: "idcard2", type: "string" },
			{ name: "tax_permit", type: "string" },
			{ name: "organization_permit", type: "string" },
			{ name: "bank_permit", type: "string" },
			{ name: "business_licence", type: "string" },
			{ name: "account_holder", type: "string" },
			{ name: "alipay", type: "string" },
			{ name: "idcard_number", type: "string" },
		],
		id: "id",
		url: "shop/all.do?where=-3",
		data: { status: 0 }
	});
	$("#dataTable").jqxDataTable({
		width: "100%",
		source: tableSource,
		pageable: true,
		pageSize: 18,
		pagerButtonsCount: 10,
		serverProcessing: true,
		columnsResize: true,
		sortable: true,
		columns: [
			{ text: "序号", width: 50, cellsRenderer: function(row) { return (row + 1).toString(); } },
			{ text: "店铺名称", dataField: "name", width: 200 },
			{ text: "联系人", dataField: "contacts", width: 120 },
			{ text: "联系电话", dataField: "telephone", width: 150, 
				cellsRenderer: function(row, column, value, rowData) {
					return value ? rowData.cellphone ? value + "/" + rowData.cellphone : value : rowData.cellphone ? rowData.cellphone: "无";
				} 
			},
			{ text: "联系人邮件", dataField: "emall", width: 150 },
            { text: "状态", dataField: "status", width: 240, 
            	cellsRenderer: function(row, column, value, rowData) {
            		return [
                    	"<input class='btn btn-sm btn-primary' type='button' value=' 通过 ' onclick='approve(this, " + rowData.id + ", 1)'/> , " + 
                    	"<input class='btn btn-sm btn-danger' type='button' value='不通过' onclick='approve(this, " + rowData.id + ", 2)'/>",
                    	"<b style='color:#008B00'>已通过</b>","<b style='color:#BB0000'>未通过</b>"][value];
            	}
            },
			{ text: "地址", dataField: "district", width: 200, 
				cellsRenderer: function(row, column, value, rowData) {
					return rowData.province + "." + rowData.city + "." + rowData.district;
				}
			},
			{ text: "街道", dataField: "street", width: 120 },
			{ text: "详细地址", dataField: "detailed_address", width: 300 },
			{ text: "简要说明", dataField: "description", minWidth: 300 },
			{ text: "支付宝账户", dataField: "alipay", width: 300
			}
        ],
	});
	$("#dataTable").on();
	$("#dataTable").on("rowDoubleClick",function(info, args){
		if(args && args.flag){
			info = args;
		}
		editingIndex = info.args.index;
		editingData = info.args.row;
	 	_editerIndex = layer.open({
			id: "sellerEditer",
			title: "查看/审核店家信息",
		    type: 1,
		    skin: 'layui-layer-rim',
		    area: ['1000px', '680px'],
		    content: 
				'<div id="seller-editer" class="form" style="height: 100%;overflow: auto;">' +
					'<input type="hidden" name="id" />' +
					'<label class="from-label" for="name">店铺名称：</label>' +
					'<input type="text" name="name" allowBlank="false" class="form-control" placeholder="店铺名称" readonly="true" />' +
					'<label class="from-label" for="contacts">联系人：</label>' +
					'<input type="text" name="contacts" allowBlank="false" class="form-control" placeholder="联系人" readonly="true" />' +
					'<label class="from-label" for="telephone">座机号码：</label>' +
					'<input type="text" name="telephone" allowBlank="false" class="form-control" placeholder="座机号码" readonly="true" />' +
					'<label class="from-label" for="cellphone">手机号码：</label>' +
					'<input type="text" name="cellphone" allowBlank="false" class="form-control" placeholder="手机号码" readonly="true" />' +
					'<label class="from-label" for="idcard_number">身份证：</label>' +
					'<input type="text" name="idcard_number" id="idcard_number" allowBlank="false" class="form-control" placeholder="身份证" readonly="true" />' +
					'<label class="from-label" for="email">E-mail：</label>' +
					'<input type="text" name="email" id="email" allowBlank="false" class="form-control" placeholder="E-mail" readonly="true" />' +
					'<label class="from-label" for="bank_name">银行名称：</label>' +
					'<input type="text" name="bank_name" allowBlank="false" class="form-control" placeholder="银行名称" readonly="true" />' +
					'<label class="from-label" for="bank_account">银行账户：</label>' +
					'<input type="text" name="bank_account" allowBlank="false" class="form-control" placeholder="银行账户" readonly="true" />' +
					'<label class="from-label" for="province">所在省份：</label>' +
					'<input type="text" name="province" class="form-control" placeholder="所在省份" readonly="true" />' +
					'<label class="from-label" for="city">所在城市：</label>' +
					'<input type="text" name="city" class="form-control" placeholder="所在城市" readonly="true" />' +
					'<label class="from-label" for="district">所在区县：</label>' +
					'<input type="text" name="district" class="form-control" placeholder="所在区县" readonly="true" />' +
					'<label class="from-label" for="street">所在街道：</label>' +
					'<input type="text" name="street" class="form-control" placeholder="所在街道" readonly="true" />' +
					'<br>' +
					'<label class="from-label" for="detailed_address">详细地址：</label>' +
					'<input type="text" name="detailed_address" allowBlank="false" class="form-control" placeholder="详细地址" readonly="true" />' +
					'<br><label class="from-label" for="logo">LOGO：</label>' +
					'<img name="logo" allowBlank="false" class="form-control" style="border: 1px solid #AAA;width:830px;height:250px;" />' +
					'<br><label class="from-label" for="idcard">身份证正面：</label>' +
					'<img name="idcard" allowBlank="false" class="form-control" style="border: 1px solid #AAA;width:830px;height:250px;" />' +
					'<br><label class="from-label" for="idcard2">身份证反面：</label>' +
					'<img name="idcard2" allowBlank="false" class="form-control" style="border: 1px solid #AAA;width:830px;height:250px;" />' +
				    '<br><label class="from-label" for="business_licence">营业执照：</label>' +
					'<img name="business_licence" allowBlank="false" class="form-control" style="border: 1px solid #AAA;width:830px;height:250px;" />' +
					'<br><label class="from-label" for="tax_permit">税务登记证：</label>' +
					'<img name="tax_permit" allowBlank="false" class="form-control" style="border: 1px solid #AAA;width:830px;height:250px;" />' +
					'<br><label class="from-label" for="organization_permit">组织机构代码证：</label>' +
					'<img name="organization_permit" allowBlank="false" class="form-control" style="border: 1px solid #AAA;width:830px;height:250px;" />' +
					'<br><label class="from-label" for="bank_permit">银行开户许可证：</label>' +
					'<img name="bank_permit" allowBlank="false" class="form-control" style="border: 1px solid #AAA;width:830px;height:250px;" />' +
					'<br><br><br>' +
				'</div>' +
				'<div class="form" style="position: absolute;bottom: 0px;width: 100%;text-align: right;background-color: #DDD;">' +
					'<span id="editer-approve">' +
						'<input type="button" class="btn btn-sm btn-primary" value="通过" onclick="editerApprove(this, 1)"/>' +
						'<input type="button" class="btn btn-sm btn-danger" value="不通过" onclick="editerApprove(this, 2)"/>' +
					'</span>' +
					'<input type="button" class="btn btn-sm btn-info" onclick="closeEditer(this)" value="返回"/>' +
				'</div>'
		});
	 	setData($("#seller-editer"), editingData);
	 	if(editingData.status){
	 		$("#editer-approve")[0].innerHTML = 
	 			["待审核","<b style='color:#008B00'>已通过</b>","<b style='color:#BB0000'>未通过</b>"][editingData.status];
	 	}
	});
});